package club.janna.rpcdemo.server.impl;

import club.janna.rpcdemo.api.UserService;
import club.janna.rpcdemo.domain.User;
import club.janna.rpcdemo.server.annotation.RPCService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RPCService(serviceName = "club.janna.rpcdemo.api.UserService")
public class UserServiceImpl implements UserService {

    private Map<Long, User> map = new HashMap<>();

    @PostConstruct
    public void init() {
        map.put(1L, new User(1L, "janna", 18, "女"));
        map.put(2L, new User(2L, "guopanbo", 18, "男"));
        map.put(3L, new User(3L, "test", 18, "女"));
    }

    @Override
    public String sayHello(String name) {
        return "Hello, " + name;
    }

    @Override
    public List<User> list() {
        List<User> users = new ArrayList<>();
        users.addAll(map.values());
        return users;
    }

    @Override
    public User getById(Long id) {
        return map.get(id);
    }
}
